

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.springframework.util.ResourceUtils;

import com.alibaba.dubbo.config.annotation.Service;
import org.w3c.dom.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;


@Service
public class ScanService {
	public static List<File> files =new ArrayList<File>();
	
	public static void main(String args[]) throws FileNotFoundException {
		String rootpath = ResourceUtils.getURL("classpath:").getPath();
//		System.out.println(rootpath);
		File file = new File(rootpath);		//获取其file对象
		 func(file);
		
		for(File ff :files) {
		String filename =	ff.getName();
			if(filename.contains(".xml")) {
				scan_xml(ff.getAbsolutePath());
			}
			
		}
	}
	
	
	private  Map<String, String> scan_service() {
		return null;
	}
	
	private static  Map<String, String> scan_xml(String path) {
		
		  //1.创建DocumentBuilderFactory对象
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        //2.创建DocumentBuilder对象
        try {
            DocumentBuilder builder = factory.newDocumentBuilder();
            Document d = builder.parse(path);
            NodeList sList = d.getElementsByTagName("select");
            System.out.println(sList.getLength());
            //element(sList);
//            node(sList);
        } catch (Exception e) {
            e.printStackTrace();
        }
		
		
		return null;
	}
	
	private  Map<String, String> scan_ConfigId() {
		return null;
	}
	
	private static List<File> func(File file){
		File[] fs = file.listFiles();
		for(File f:fs){
			if(f.isDirectory())	//若是目录，则递归打印该目录下的文件
				func(f);
			if(f.isFile())		//若是文件，直接打印
				files.add(f);
//				System.out.println(f);
		}
		return files;
	}
	
	  //用Element方式
    public static void element(NodeList list){
        for (int i = 0; i <list.getLength() ; i++) {
            Element element = (Element) list.item(i);
            NodeList childNodes = element.getChildNodes();
            for (int j = 0; j <childNodes.getLength() ; j++) {
                if (childNodes.item(j).getNodeType()==Node.ELEMENT_NODE) {
                    //获取节点
                    System.out.print(childNodes.item(j).getNodeName() + ":");
                    //获取节点值
                    System.out.println(childNodes.item(j).getFirstChild().getNodeValue());
                }
            }
        }
    }

    public static void node(NodeList list){
        for (int i = 0; i <list.getLength() ; i++) {
            Node node = list.item(i);
            System.out.println(node.getFirstChild());;
            NodeList childNodes = node.getChildNodes();
//            for (int j = 0; j <childNodes.getLength() ; j++) {
//                if (childNodes.item(j).getNodeType()==Node.ELEMENT_NODE) {
//                    System.out.print(childNodes.item(j).getNodeName() + ":");
//                    System.out.println(childNodes.item(j).getFirstChild().getNodeValue());
//                }
//            }
        }
    }
	




}
